<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/5/19
 * Time: 14:49
 */

namespace Home\Service;


use Common\Common\Service;

use Home\Component\ApplyComponent;
use Home\Exception\HomeException;
use Home\Request\Apply\CheckApplyRequest;
use Home\Response\CheckApplyResponse;

class CheckApplyService implements Service
{
    public function run(CheckApplyRequest $request = null)
    {
        if ($request->issetUserId() == false)
            throw new HomeException(10001);
        if ($request->verifyUserId() == false)
            throw new HomeException(10002);
        if ($request->IsUserIdInRange() == false)
            throw new HomeException(10003);

        $user_id = $request->getUserId();
        $component = new ApplyComponent();
        $response = new CheckApplyResponse();
        try {
            $data = $component->checkApply($user_id);
            if (is_null($data)) {
                $response->setItIsNull();
            }else{
                $response->setData($data);
            }
        } catch (HomeException $e) {
            throw new HomeException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}